<?php
class MyUserIdentity extends CUserIdentity
{
	/**
	 * 管理员验证
	 */
	public function admin_authenticate()
    {
    	// 执行防注入处理
    	
		$row = Admin::model()->find('username=:name',array(':name' => $this->username));

        if(!$row || $row->password !== MyController::hash_password($this->password))
        {
        	return FALSE;
        }
        else
        {
        	//更新登陆后的信息
        	$row->login_time = date('Y-m-d H:i:s');
        	$row->login_ip = MyController::getUserHostAddress();
        	$row->login_times = $row->login_times + 1;
        	$row->save();
        	
        	$this->setState('admin_is_login', TRUE);
        	$this->setState('user_is_login', TRUE);
        	$this->setState('uid', $row->id);
        	$this->setState('username', $row->username);
        	$this->username = $row->username;
            return $row->id;
        }
    }
}